<template>
	<view class="my-page">
		<u-navbar :title="title" bgColor="rgba(255,255,255,0.0)" :auto-back="true" :placeholder="true">
			<view slot="right" @click="goadd(type)" class="nav-text">
				添加账户
			</view>
		</u-navbar>
		<view class="list-box">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="head">
					<image v-if="type!=3&&type!=4" :src="item.qrcode" mode=""></image>
					<view class="head-info">
						<view class="name" v-if="type==1">名称:{{item.payNike}}</view>
						<view class="name" v-if="type==2">名称:{{item.wxNike}}</view>
						<view class="name" v-if="type==3">开户行:{{item.openBank}}</view>
						<view class="account" v-if="type==1">账号:{{item.payAccount}}</view>
						<view class="account" v-if="type==3">账号:{{item.card}}</view>
						<view class="account" v-if="type!=4">
							姓名:{{item.username}}
						</view>
						<view class="account" v-if="type == 4">
							USDT地址:{{item.url}}
						</view>
					</view>
				</view>
				<view class="btn-box">
					<u-button class="btn" type="error" shape="circle" text="删除" @click="godel(item.id)"></u-button>
				</view>
			</view>

		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				title: '',
				page: 1,
				list: [],
				status: 'loadmore',
			}
		},
		onLoad(e) {
			this.type = e.type
			if (this.type == 1) {
				this.title = '支付宝列表'
				this.getlist('/api/member/payoutInfo/zfb/list')
			}
			if (this.type == 2) {
				this.title = '微信列表'
				this.getlist('/api/member/payoutInfo/wx/list')
			}
			if (this.type == 3) {
				this.title = '银行卡列表'
				this.getlist('/api/member/payoutInfo/bank/list')
			}
			if (this.type == 4) {
				this.title = 'USDT列表'
				this.getlist('/api/member/payoutInfo/usdt/list')
			}
		},
		onShow() {
			this.page = 1
			if (this.type == 1) {
				this.getlist('/api/member/payoutInfo/zfb/list')
			}
			if (this.type == 2) {
				this.getlist('/api/member/payoutInfo/wx/list')
			}
			if (this.type == 3) {
				this.getlist('/api/member/payoutInfo/bank/list')
			}
			if (this.type == 4) {
				this.getlist('/api/member/payoutInfo/usdt/list')
			}
		},
		onReachBottom() {
			this.page = this.page + 1
			this.status = 'loading';
			if (this.type == 1) {
				this.getlist('/api/member/payoutInfo/zfb/list')
			}
			if (this.type == 2) {
				this.getlist('/api/member/payoutInfo/wx/list')
			}
			if (this.type == 3) {
				this.getlist('/api/member/payoutInfo/bank/list')
			}
			if (this.type == 4) {
				this.getlist('/api/member/payoutInfo/usdt/list')
			}
		},
		methods: {
			godel(id) {
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否删除此账户！',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								mask: true
							})
							let params = {
								id: id,
							}
							if (app.type == 1) {
								app.$Request({
									method: 'POST',
									url: '/api/member/payoutInfo/zfb/del',
									data: params,
									ismsg: true,
								}).then(res => {
									uni.hideLoading()
									if (res.code == 200) {
										app.page = 1
										app.getlist('/api/member/payoutInfo/zfb/list')
									}
								})
							}
							if (app.type == 2) {
								app.$Request({
									method: 'POST',
									url: '/api/member/payoutInfo/wx/del',
									data: params,
									ismsg: true,
								}).then(res => {
									uni.hideLoading()
									if (res.code == 200) {
										app.page = 1
										app.getlist('/api/member/payoutInfo/wx/list')
									}
								})
							}
							if (app.type == 3) {
								app.$Request({
									method: 'POST',
									url: '/api/member/payoutInfo/bank/del',
									data: params,
									ismsg: true,
								}).then(res => {
									uni.hideLoading()
									if (res.code == 200) {
										app.page = 1
										app.getlist('/api/member/payoutInfo/bank/list')
									}
								})
							}
							if (app.type == 4) {
								app.$Request({
									method: 'POST',
									url: '/api/member/payoutInfo/usdt/del',
									data: params,
									ismsg: true,
								}).then(res => {
									uni.hideLoading()
									if (res.code == 200) {
										app.page = 1
										app.getlist('/api/member/payoutInfo/usdt/list')
									}
								})
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			goadd(type) {
				uni.navigateTo({
					url: '/pages/my/account/receive/add?type=' + type
				})
			},
			getlist(url) {
				let params = {
					pageNum: this.page,
					pageSize: 10
				}
				this.$Request({
					method: 'GET',
					url: url,
					data: params,
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						if (res.rows.length < 10) {
							this.status = 'nomore';
						}
						if (this.page == 1) {
							this.list = res.rows
						} else {
							this.list = [...this.list, ...res.rows]
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-page {
		min-height: calc(100vh - 91rpx);
		background-image: url('../../../../static/goods/top-bg.png');
		background-size: 100% 561rpx;
		background-repeat: no-repeat;
		padding: 30rpx;

		.nav-text {
			font-size: 26rpx;
		}

		.list-box {
			.list {
				background-color: #ffffff;
				border-radius: 10rpx;
				padding: 20rpx;
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.btn-box {
					.btn {
						width: 140rpx;
						height: 60rpx;
					}
				}

				.head {
					display: flex;
					align-items: center;

					image {
						width: 140rpx;
						height: 140rpx;
					}

					.head-info {
						margin-left: 20rpx;

						.name {
							font-size: 28rpx;
							font-weight: 900;
						}

						.account {
							width:300rpx;
							overflow: hidden;
							/*内容超出后隐藏*/
							text-overflow: ellipsis;
							/*超出内容显示为省略号*/
							white-space: nowrap;
							/*文本不进行换行*/
							margin-top: 10rpx;
							font-size: 26rpx;
							color: #333;
						}
					}
				}
			}
		}

	}
</style>